﻿using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;

namespace EasyXaf.EntityDesigner.Controllers;

public abstract class DisableNewAndDeleteViewController : ViewController
{
    private NewObjectViewController _newObjectViewController;
    private DeleteObjectsViewController _deleteObjectsViewController;

    protected override void OnActivated()
    {
        base.OnActivated();

        _newObjectViewController = Frame.GetController<NewObjectViewController>();
        if (_newObjectViewController != null)
        {
            _newObjectViewController.Active[Name] = false;
        }

        _deleteObjectsViewController = Frame.GetController<DeleteObjectsViewController>();
        if (_deleteObjectsViewController != null)
        {
            _deleteObjectsViewController.Active[Name] = false;
        }
    }

    protected override void OnDeactivated()
    {
        _newObjectViewController?.Active.RemoveItem(Name);
        _deleteObjectsViewController?.Active.RemoveItem(Name);

        base.OnDeactivated();
    }
}
